package com.whut.whw.topic;

import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.TextView;

import com.whut.whw.R;
import com.whut.whw.base.BaseFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * <pre>
 *  @Decription 专题Fragment
 *  @datetime 2017/06/07 8:55
 *  @author 忘尘无憾
 *  @version
 * </pre>
 */
public class TopicFragment extends BaseFragment {

    public static TopicFragment newInstance() {
        return new TopicFragment();
    }

    private GridView topic_gv;
    private Toolbar toolbar;


    @Override
    public View initView(LayoutInflater inflater) {
        View rootView = inflater.inflate(R.layout.fragment_topic, null);
        topic_gv = (GridView) rootView.findViewById(R.id.topic_gv);
        //设置toolbar
        toolbar = (Toolbar) rootView.findViewById(R.id.toolbar);
        toolbar.setTitle(R.string.topic_title);
        toolbar.setTitleTextColor(ContextCompat.getColor(context,R.color.white));
        return rootView;
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        List<TopicModel> list = new ArrayList<>();
        list.add(new TopicModel("明信片", "总有一个不同的属于你", "https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo_top_ca79a146.png"));
        list.add(new TopicModel("简书", "发现不一样", "http://cdn2.jianshu.io/assets/web/logo-58fd04f6f0de908401aa561cda6a0688.png"));
        list.add(new TopicModel("哈哈时间和咖啡数据的杀空间大就是看动画", "发现不一样", "https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=4186807976,1707145605&fm=23&gp=0.jpg"));
        list.add(new TopicModel("哈哈", "发现不一样", "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=3581274228,2829935773&fm=23&gp=0.jpg"));
        list.add(new TopicModel("哈哈", "发现不一样", "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2297282265,2663255620&fm=23&gp=0.jpg"));
        list.add(new TopicModel("明信片", "总有一个不同的属于你", "https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo_top_ca79a146.png"));
        TopicStyleAdapter topicAdapter = new TopicStyleAdapter(getActivity(), list);
        topic_gv.setAdapter(topicAdapter);
    }

    @Override
    public void setListener() {
        //设置GridView的监听事件
        topic_gv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                getUiDelegate().toastShort(((TextView) view.findViewById(R.id.topic_title_tv)).getText().toString());
            }
        });
    }
}
